package cn.kgc.student.service.impl;

import cn.kgc.student.pojo.Student;
import cn.kgc.student.dao.StudentMapper;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import cn.kgc.student.utils.Page;
import javax.annotation.Resource;
import cn.kgc.student.vo.StudentParam;
import com.alibaba.dubbo.config.annotation.Service;
import cn.kgc.student.service.StudentService;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.StringRedisTemplate;

/**
* 描述：学生 服务实现层接口
* @author 魏耀
* @date 2019/07/22
*/
@Service(interfaceClass=StudentService.class,timeout = 60000,retries = 2,version="1.1")
public class StudentServiceImpl implements StudentService{
	@Resource
	private StudentMapper studentMapper;

 	/**
    * 描述：根据Id获取Student对象
    * @param id
    */
    public Student findById(Serializable id){
    	return studentMapper.findById(id);
    }
    /**
    * 描述：获取所有的Student对象
    */
    public List<Student> findAll(){
    	return studentMapper.findAll();
    }

	/**
    * 描述：新增保存Student对象
    */
    public int save(Student student){
    	return  studentMapper.save(student);
    }

	/**
    * 描述：根据Id删除Student对象
    * @param id
    */
    public int delete(Serializable id){
    	return  studentMapper.delete(id);
    }
	
	/**
    * 描述：更新Student对象
    */
    public int update(Student student){
    	return  studentMapper.update(student);
    }
    
    /**
     * 根据不确定的条件，动态查询
     */
    public List<Student> query(StudentParam param){
    	return  studentMapper.query(param);
    }
    
    /**
     * 根据不确定的条件，动态分页查询
     */
    public Page queryByPage(StudentParam param){
    	Page page = new Page();
    	if(param.isPage()){
			int totalCount = studentMapper.getCount(param);
			int totalPageCount = (totalCount-1)/page.getPageSize()+1;
			if(param.getPageIndex()<1){
				param.setPageIndex(1);
			}else if(param.getPageIndex()>totalPageCount){
				param.setPageIndex(totalPageCount);
			}
			List list = studentMapper.query(param);

			page.setTotalCount(totalCount);
			page.setTotalPageCount(totalPageCount);
    		page.setPageNo(param.getPageIndex());
    		page.setPageSize(param.getSize());
			page.setList(list);
		}
    	return page;
    	
    }

}
